/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.apache.shiro.session.mgt;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.session.Session;
import org.apache.shiro.web.session.mgt.WebSessionContext;

/**
 * <p>创建自定义session</p>
 * <p>添加一些自定义参数</p>
 * <p>如 用户登陆的系统ip</p>
 * <p>用户状态(在线,隐身,强制退出)</p>
 * <p>等 如当前用户所在系统等</p>
 * <p>@author Henry.Y</p>
 * <p>@date 2019-09-10</p>
 */
public class OnlineSessionFactory implements SessionFactory{

	public Session createSession(SessionContext intiData){
		OnlineSession session= new OnlineSession();
		if(null != intiData && intiData instanceof WebSessionContext){
			WebSessionContext sessionContext= (WebSessionContext)intiData;
			HttpServletRequest request= (HttpServletRequest)sessionContext.getServletRequest();
			if(null != request){
				session.setHost(IpUtils.getIpAddr(request));
				session.setUserAgnet(request.getHeader("User-Agent"));
				session.setSystemHost(request.getLocalAddr()+":"+request.getLocalPort());
			}
		}
		return session;
	}
}
